package com.bank.service;

import com.bank.api.DollarBankTransferApi;
import com.bank.api.model.AmountExchange;
import com.bank.api.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.hmily.annotation.HmilyTCC;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
@Slf4j
public class DollorTransferApiImpl implements DollarBankTransferApi {


    @Autowired
    private DollarBankTransferInnerService dollarBankTransferInnerService;

    // try
    //设计账户表，冻结资产表

    @Override
    @HmilyTCC(confirmMethod = "confirm", cancelMethod = "cancel")
    public Response transfer(AmountExchange amountExchange) {
        dollarBankTransferInnerService.transfer(amountExchange);
        return Response.wrapSuccess();
    }

    /**
     * confirm 直接完成流水
     *
     * @param amountExchange
     * @return
     */
    public boolean confirm(AmountExchange amountExchange) {
        dollarBankTransferInnerService.confirm(amountExchange);
        return Boolean.TRUE;
    }

    public boolean cancel(AmountExchange amountExchange) {
        dollarBankTransferInnerService.cancel(amountExchange);
        return Boolean.TRUE;
    }

}
